package com.chinacoal.hr.levelimpl.service.impl;

import com.chinacoal.hr.levelapi.entity.FileInfo;
import com.chinacoal.hr.levelimpl.dao.FileInfoDao;
import com.chinacoal.hr.levelimpl.service.FileInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: YunTao.Li
 * @create: 2019-12-04 22:32
 * @description:
 **/
@Service
public class FileInfoServiceImpl implements FileInfoService {

    @Autowired
    public FileInfoDao fileInfoDao;


    /**
     * 添加文件信息
     *
     * @param record :
     * @return : java.util.Map<java.lang.String,java.lang.String>
     * @author : YunTao.Li
     * @date : 2019/12/4 2019/12/4
     */
    @Override
    public Map<String, String> addFileInfo(FileInfo record) throws Throwable {
        Map<String, String> result = new HashMap<String, String>();
        result.put("code", "-1");
        try {
            this.fileInfoDao.insertFileInfo(record);
        } catch (Throwable e) {
            e.printStackTrace();
            throw e;
        }
        result.put("code", "1");
        return result;
    }

    /**
     * 获得不带分页的文件信息列表
     *
     * @param condition :
     * @return : java.util.List<com.chinacoal.hr.levelimpl.entity.FileInfo>
     * @author : YunTao.Li
     * @date : 2019/12/4 2019/12/4
     */
    @Override
    public List<FileInfo> getFileInfosWithOutPage(Map<String, Object> condition) throws Throwable {
        List<FileInfo> fileInfos = this.fileInfoDao.getFileInfoListWithOutPage(condition);

        return fileInfos;
    }

    /**
     * 将属于某业务的文件列表的临时业务id换成真正的业务id
     *
     * @param tempPaDocId :
     * @param realPaDocId :
     * @return : java.util.Map<java.lang.String,java.lang.String>
     * @author : YunTao.Li
     * @date : 2019/12/5 2019/12/5
     */
    public Map<String, String> updatePaDocId(String tempPaDocId, String realPaDocId) throws Throwable {
        Map<String, String> result = new HashMap<String, String>();
        result.put("code", "-1");
        try {
            FileInfo template = new FileInfo();
            template.setPaDocId(tempPaDocId);

            FileInfo value = new FileInfo();
            value.setPaDocId(realPaDocId);

            this.fileInfoDao.updateFileInfo(template, value);
        } catch (Throwable e) {
            e.printStackTrace();
            throw e;
        }
        result.put("code", "1");
        return result;
    }

    @Override
    public FileInfo getFileInfo(String fileId) throws Throwable {
        Map<String, Object> condition = new HashMap<String, Object>();
        condition.put("fileId", fileId);
        return this.fileInfoDao.getFileInfo(condition);
    }

    /**
     * 删除文件信息
     *
     * @param fileId :
     * @return : java.util.Map<java.lang.String,java.lang.String>
     * @author : YunTao.Li
     * @date : 2020/1/2 2020/1/2
     */
    @Override
    public Map<String, String> deleteFileInfo(String fileId) {
        Map<String, String> result = new HashMap<String, String>();
        result.put("code", "-1");
        try {
            this.fileInfoDao.deleteBizTravelById(fileId);
        } catch (Throwable e) {
            e.printStackTrace();
            throw e;
        }
        result.put("code", "1");
        return result;
    }
}
